package com.app.nba.service;

import com.app.nba.dao.UserDao;
import com.app.nba.pojo.LoginVO;
import com.app.nba.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class UserService {

    @Autowired
    private UserDao userDao;

    public String login(LoginVO user) {
        int row = userDao.login(user);
        if (row == 1) {
            return "OK";
        } else {
            return "登录失败";
        }
    }

    public String register(LoginVO loginVO) {
        User user = new User();
        user.setAccount(loginVO.getAccount());
        user.setPassword(loginVO.getPassword());
        User selectOne = userDao.selectOne(user);
        if (selectOne == null) {
            userDao.register(loginVO);
            return "OK";
        }
        return "用户已存在";
    }

    public User selectOne(User user) {
        return userDao.selectOne(user);
    }

    public void edit(User user) {
        user.setCreateTime(new Date());
        userDao.edit(user);
    }

    public User checkAccount(User user) {
        return userDao.checkAccount(user);
    }

    public User findById(Integer userId) {
        return userDao.findById(userId);
    }
}
